/*
TimerPinDirect_1.pde -- timers act directly on pins --first example with fixed speeds

Copyright (c) 2010 Ed Bennett.  All rights reserved. 

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


// Timer commands usually take a channel number and/or a 
// time-value. 
//
// The unit of time is is called a blink. The duration 
// of a blink is related to an AVR jiffy. See
// http://en.wikipedia.org/wiki/Jiffy_%28time%29
//
// This example uses direct control of the pins from the timer channels.
// This method uses less processor power than callbacks or flag polling.
// (see the other examples)


/*
This Ard. code does a sq. wave w/ a period of about 0.28ms (oscilloscope):

    // using pin-direct mode, you need to set the pin-high
    // and pin-low times seperately
    Timer.setHighTime(0, 1); // (channel, value)
    Timer.setLowTime(0, 1); 
*/

#include <TimerScheduler.h>

// hardware pins
int LED0 = 13;
int LED1 = 12;
int LED2 = 11;

int outval0 = 0;
int outval1 = 0;
int outval2 = 0;


void setup()
{   
  pinMode(LED0, OUTPUT); 
  pinMode(LED1, OUTPUT); 
  pinMode(LED2, OUTPUT);
  
  Timer.begin();        // start the hardware timer
  
  Timer.setMasterPeriod(200); // sets the master timer -- a small number will hang
    //the cpu. default is 200
  
  // attach LED pins to timer channels
  Timer.attachPin(0, LED0); // (channel, value)
  Timer.attachPin(1, LED1);
  Timer.attachPin(2, LED2); 

  // using pin-direct mode, you need to set the pin-high
  // and pin-low times seperately
  Timer.setHighTime(0,128); // (channel, value)
  Timer.setLowTime(0, 127); 
  
  Timer.setHighTime(1,4000);
  Timer.setLowTime(1, 4000);
  
  Timer.setHighTime(2, 256);
  Timer.setLowTime(2, 63);
  
  Timer.start(0);       // (channel)
  Timer.start(1); 
  Timer.start(2); 
}


// You can put things in loop(), if you like,
// but it's not required.

void loop()
{
}
